#!/usr/bin/bash

char_flag="*"
char_num=43

front_black='30'
front_red='31'
front_green='32'
front_yellow='33'
front_blue='34'
front_purple='35'
front_cyan='36'
front_white='37'

back_black='40'
back_red='41'
back_green='42'
back_yellow='43'
back_blue='44'
back_purple='45'
back_cyan='46'
back_white='47'

font_underline='04'
color_flash='05'

color_prefix='\e['
color_suffix='\e[0m'
color_sep=';'
color_flag='m'

function openharmony_menu() {
  cyan_black=${color_prefix}${front_cyan}${color_sep}${back_black}${color_flag}
  echo -e "* ${cyan_black}OpenHarmony Version${color_suffix}                     *"
  echo -e "*   OpenHarmony master         prese 1.1  *"
  echo -e "*   OpenHarmony-3.0-LTS        press 1.2  *"
  echo -e "*   OpenHarmony-3.1-Release    press 1.3  *"
  echo -e "*   OpenHarmony-3.2-Release    press 1.4  *"
  echo -e "*   OpenHarmony-4.1-Release    press 1.5  *"
  echo -e "*   OpenHarmony-v3.0-LTS       press 1.20 *"
  echo -e "*   OpenHarmony-v3.2-Release   press 1.21 *"
  echo -e "*   OpenHarmony-v3.2.2-Release press 1.22 *"
  echo -e "*   OpenHarmony-v4.0-Release   press 1.23 *"
  echo -e "*   OpenHarmony-clang-master   press 1.30 *"
}

function qemu_menu() {
  green_black=${color_prefix}${front_green}${color_sep}${back_black}${color_flag}
  echo -e "* ${green_black}Qemu Version${color_suffix}                            *"
  echo -e "*   qemu-riscv64               press 2.1  *"
}

function thead_menu() {
  yellow_black=${color_prefix}${front_yellow}${color_sep}${back_black}${color_flag}
  echo -e "* ${yellow_black}Thead Version${color_suffix}                           *"
  echo -e "*   thead-v3.2.2-release       press 3.1  *"
  echo -e "*   thead-tablet               press 3.2  *"
  echo -e "*   thead-cartablet            press 3.3  *"
  echo -e "*   thead-cloud                press 3.4  *"
  echo -e "*   dayu800-v4.0-release       press 3.11 *"
  echo -e "*   dayu800-3.2-Release-TPC    press 3.12 *"
  echo -e "*   dayu800-v3.2.2-Release-TPC press 3.13 *"
  echo -e "*   chromium                   press 3.21 *"
}

function riscv_adapt_menu() {
  blue_black=${color_prefix}${front_blue}${color_sep}${back_black}${color_flag}
  echo -e "* ${blue_black}Riscv Adapt Version${color_suffix}                     *"
  echo -e "*   riscv-master               press 4.1  *"
  echo -e "*   riscv-weekly0905           press 4.2  *"
  echo -e "*   riscv-3.2-Release          press 4.3  *"
}

function local_menu() {
  purple_black=${color_prefix}${front_purple}${color_sep}${back_black}${color_flag}
  echo -e "* ${purple_black}Local Version${color_suffix}                           *"
  echo -e "*   dayu800_v3.2.2_debug       press 5.10 *"
  echo -e "*   dayu800_v4.0_debug         press 5.11 *"
  echo -e "*   bes2600                    press 5.12 *"
  echo -e "*   rk_v3.2.2_debug            press 5.20 *"
  echo -e "*   rk_v4.0_debug              press 5.21 *"
  echo -e "*   android-12.1.0_r4          press 5.30 *"
  echo -e "*   android-13.0.0_r6          press 5.31 *"
  echo -e "*   android-13.0.0_r80         press 5.32 *"
  echo -e "*   android-14.0.0_r10         press 5.33 *"
  echo -e "*   virt-dev                   press 5.40 *"
}

function custom_tag_menu() {
  purple_black=${color_prefix}${front_cyan}${color_sep}${back_black}${color_flag}
  echo -e "* ${purple_black}Custom Tag${color_suffix}                              *"
  echo -e "*   weekly_2023090             press 6.1  *"
  echo -e "*   dayu800-master             press 6.2  *"
}

function remora_menu() {
  purple_black=${color_prefix}${front_purple}${color_sep}${back_black}${color_flag}
  echo -e "* ${purple_black}Remora    ${color_suffix}                              *"
  echo -e "*   remora_rk3588              press 7.1  *"
  echo -e "*   remora_dayu800             press 7.2  *"
}

function main_menu() {
  # 打印头
  printf "%-${char_num}s\n" "${char_flag}" | sed "s/ /${char_flag}/g"

  red_flash=${color_prefix}${front_red}${color_sep}${color_flash}${color_flag}
  # 打印欢迎语句
  echo -e "*  ${red_flash}Welcome to download OpenHarmony Code${color_suffix}   *"
  echo -e "* Please Choice OpenHarmony SDK:          *"
  openharmony_menu
  qemu_menu
  thead_menu
  riscv_adapt_menu
  git_name=$(git config user.name)
  if [[ ${git_name} == "wenfei6316" ]]; then
    local_menu
    custom_tag_menu
  fi
  remora_menu
  # 打印尾
  printf "%-${char_num}s\n" "${char_flag}" | sed "s/ /${char_flag}/g"
}
